home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacWorld 1999 August
/
Macworld (1999-08).dmg
/
Shareware World
/
Info
/
For Developers
/
MADE 1.4.0
/
Essentials
/
Essential Menus.c
< prev
next >
Wrap
Text File
|
1999-05-26
|
6KB
|
235 lines
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* MADE - Macintosh Application Development Essentials */
/* --------------------------------------------------- */
/* (c) Sig Software, http://www.sigsoftware.com/ */
/* */
/* These files can only be used for experimental purposes. To obtain */
/* fully commented code, source code for the functions in Essential */
/* Extras.h and permission for usage in final projects, you must */
/* purchase a license. See documentation for more information. */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* Essential Menus.c */
/* ----------------- */
/* */
/* Menu handling, Drag Manager and cursor routines. */
/* */
/* Version 1.0.0 - 10th November 1996 */
/* Version 1.0.1 - 4th June 1997 - Resets port in DragTrackHandler */
/* Version 1.1.0 - 29th January 1998 - New OS function names */
/* Version 1.2.0 - 20th November 1998 - Reworked dragging code */
/* Version 1.4.0 - 26th May 1999 - Hide errors during drags */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "Essential Headers.h"
#include "Essential Prototypes.h"
#if Use_Drag_Manager
#include <Drag.h>
Boolean hasDragManager=false;
// No support is provided here for data send procedures, but these can be added if needed
pascal OSErr DragTrackHandler(DragTrackingMessage, WindowPtr, void *, DragReference);
pascal OSErr DragReceivHandler(WindowPtr, void*, DragReference);
DragTrackingHandlerUPP DragTrackUPP;
DragReceiveHandlerUPP DragReceivUPP;
#endif
// Menu item switching is based on the fact that the upper 16 bits of the value returned by
// the system are the menu's ID and the lower 16 bits are the item number chosen in that menu.
// Just remember these are IDs defined within the MENU resource, not the resource ID itself.
enum {
AppleStart=128*65536,
AppleAbout,
AppleSep1,
AppleItems,
AppleEnd=128*65536+65535
};
Error InitMenuBar()
{
Error error=0;
Handle theMenuBar;
MenuHandle theAppleMenu;
theMenuBar=GetNewMBar(128);
error=TestResError(theMenuBar);
_i(error)
SetMenuBar(theMenuBar);
DisposeHandle(theMenuBar);
theAppleMenu=GetMenuHandle(128);
AppendResMenu(theAppleMenu, 'DRVR');
DrawMenuBar();
_e
return error;
}
void SelectMenuItem(long selection)
{
Str255 menuItemName;
if (selection>=AppleItems && selection<=AppleEnd) {
GetMenuItemText(GetMenuHandle(128), (short)(selection-AppleStart), menuItemName);
OpenDeskAcc(menuItemName);
} else
MyPerformMenu(selection);
HiliteMenu(0);
}
void SetMenuItemEnabled(short menuID, short menuItem, Boolean enable)
{
MenuHandle menuHandle;
menuHandle=GetMenuHandle(menuID);
if (enable)
EnableItem(menuHandle, menuItem);
else
DisableItem(menuHandle, menuItem);
}
void ShowResCursor(short cursorID)
{
CursPtr theCursor;
theCursor=*GetCursor(cursorID);
SetCursor(theCursor);
}
#if Use_Drag_Manager
// In this model, a single Track and Receive handler is used for all drags. You can make
// separate ones for each window. Also, the refCon parameter is left at zero here.
Error InitDragManager()
{
Error error=0;
hasDragManager=true;
DragTrackUPP=NewDragTrackingHandlerProc(DragTrackHandler);
error=InstallTrackingHandler(DragTrackUPP, 0, 0);
TestError(error);
_i(error);
DragReceivUPP=NewDragReceiveHandlerProc(DragReceivHandler);
error=InstallReceiveHandler(DragReceivUPP, 0, 0);
TestError(error);
_e
return error;
}
pascal OSErr DragTrackHandler(DragTrackingMessage message, WindowPtr inWindow,
void* refCon, DragReference dragRef)
{
Point localPoint;
DragAttributes attributes;
RgnHandle region;
GrafPtr oldPort;
RGBColor backColor;
Error error=0;
if (HideErrors(&error)) {
error=GetDragAttributes(dragRef, &attributes);
_i(error)
GetPort(&oldPort);
SetPort(inWindow);
GetBackColor(&backColor);
BackColor(whiteColor);
switch (message) {
case kDragTrackingInWindow:
if (attributes&kDragHasLeftSenderWindow) {
error=GetDragMouse(dragRef, &localPoint, 0);
_i(error)
GlobalToLocal(&localPoint);
region=MyGetDragRegion(inWindow, localPoint, dragRef);
if (region) {
ShowDragHilite(dragRef, region, true);
DisposeRgn(region);
} else
HideDragHilite(dragRef);
}
break;
case kDragTrackingLeaveWindow:
HideDragHilite(dragRef);
break;
}
RGBBackColor(&backColor);
SetPort(oldPort);
_e
ShowErrors();
}
return error;
}
pascal OSErr DragReceivHandler(WindowPtr inWindow, void* refCon, DragReference dragRef)
{
Error error=0;
WindowPtr oldPort;
Point localPoint;
RGBColor backColor;
if (HideErrors(&error)) {
error=GetDragMouse(dragRef, &localPoint, 0);
_i(error)
GetPort(&oldPort);
SetPort(inWindow);
GetBackColor(&backColor);
BackColor(whiteColor);
HideDragHilite(dragRef);
RGBBackColor(&backColor);
GlobalToLocal(&localPoint);
error=MyReceiveDrag(inWindow, localPoint, dragRef);
SetPort(oldPort);
_e
ShowErrors();
}
return error;
}
void CreateDragRegion(RgnHandle region)
{
RgnHandle subtractRgn;
Point dummyPoint;
subtractRgn=NewRgn();
CopyRgn(region, subtractRgn);
InsetRgn(subtractRgn, 1, 1);
DiffRgn(region, subtractRgn, region);
DisposeRgn(subtractRgn);
dummyPoint.h=dummyPoint.v=0;
LocalToGlobal(&dummyPoint);
OffsetRgn(region, dummyPoint.h, dummyPoint.v);
}
#endif